package com.hemerasolutions.v2trainer.model.exercise.executions;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.MapsId;

import com.hemerasolutions.v2trainer.model.training.TrainingType;
import com.hemerasolutions.v2trainer.model.unit.intensity.IntensityUnit;

@Entity
public class AssociationET implements Serializable{
 
	private static final long serialVersionUID = 1L;

	@EmbeddedId
	@Column(name="pk")
	private AssociationETPK pk = new AssociationETPK() ;


    //MapsId refers to the name of the property in the embedded Id
    @MapsId("executionId")
    @JoinColumn(name="execution_id")
    @ManyToOne	
	private Execution execution;
	
    //MapsId refers to the name of the property in the embedded Id
    @MapsId("trainingTypeId")
    @JoinColumn(name="trainingType_id")
    @ManyToOne
    private TrainingType trainingType;
	
    @ManyToMany
	private List<IntensityUnit> intensityUnits;

	public AssociationET() {
		super();
	}

	
	public AssociationET(Execution execution, TrainingType trainingType) {
		super();
		this.execution = execution;
		this.trainingType = trainingType;
	}



	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public AssociationETPK getPk() {
		return pk;
	}

	public Execution getExecution() {
		return execution;
	}

	public TrainingType getTrainingType() {
		return trainingType;
	}

	public List<IntensityUnit> getIntensityUnits() {
		return intensityUnits;
	}

	public void setPk(AssociationETPK pk) {
		this.pk = pk;
	}

	public void setExecution(Execution execution) {
		this.execution = execution;
	}

	public void setTrainingType(TrainingType trainingType) {
		this.trainingType = trainingType;
	}

	public void setIntensityUnits(List<IntensityUnit> intensityUnits) {
		this.intensityUnits = intensityUnits;
	}


	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((execution == null) ? 0 : execution.hashCode());
		result = prime * result + ((pk == null) ? 0 : pk.hashCode());
		result = prime * result
				+ ((trainingType == null) ? 0 : trainingType.hashCode());
		return result;
	}


	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		AssociationET other = (AssociationET) obj;
		if (execution == null) {
			if (other.execution != null) {
				return false;
			}
		} else if (!execution.equals(other.execution)) {
			return false;
		}
		if (pk == null) {
			if (other.pk != null) {
				return false;
			}
		} else if (!pk.equals(other.pk)) {
			return false;
		}
		if (trainingType == null) {
			if (other.trainingType != null) {
				return false;
			}
		} else if (!trainingType.equals(other.trainingType)) {
			return false;
		}
		return true;
	}


	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "AssociationET [pk=" + pk + ", execution=" + execution
				+ ", trainingType=" + trainingType + "]";
	}

	
    
}
 
